<?php

namespace app\api\controller;

use addons\epay\library\Service;
use app\admin\model\goods\Order;
use app\common\controller\Api;
use app\common\controller\Payment;
use think\Controller;
use think\Db;
use think\Request;


class Competitionlists extends Api
{
    private static $model;
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = '*';


    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        self::$model = new \app\common\model\CompetitionLists();
    }

    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function lists()
    {
        $pageSize = input('pagesize', 15);

        $type = input('type', 1);
        if (!in_array($type, [1, 2])) {
            $this->error('参数非法！');
        }

        $now = date('Y-m-d H:i:s', time());
        if ($type == 1) {
            $map = [
                'status' => 1,
                'start_time' => ['>', $now]
            ];
        } else {
            $map = [
                'status' => 1,
                'start_time' => ['<', $now]
            ];
        }

        $groundId = input('ground_id');
        if ($groundId) {
            $map['ground_id'] = $groundId;
        }

        $order = input('order', 'createtime');
        $sort = input('sort', 'desc');

        $is_hot = input('is_hot');
        if ($is_hot == 1) {
            $order = 'sell_num';
            $start = 0;
        }

        $list = self::$model->where($map)->order($order . ' ' . $sort)->paginate($pageSize);
        $this->success('赛事列表', $list);
    }

    public function read()
    {
//        $userId = $this->auth->id;
        $id = input('id');
        $row_info = self::$model->find($id);
        if (!$row_info) {
            $this->error('该赛事不存在！');
        }

        $this->success('赛事详情', $row_info);
    }
}
